/**
   renderer.h - Created by Timothy Morey on 12/13/2011.
*/

#ifndef __RENDERER_H
#define __RENDERER_H

#include <pthread.h>

class VisServer;

class Renderer
{
public:
  Renderer(unsigned char did, pthread_barrier_t* barrier, VisServer* vis);
  ~Renderer();

public:
  double GetAverageGPUTime() const { return _AverageGPUTime; }
  double GetAverageCPUInnerTime() const { return _AverageCPUInnerTime; }
  double GetAverageCPUOuterTime() const { return _AverageCPUOuterTime; }
  unsigned int GetCurrentStep() const { return _CurStep; }
  unsigned char GetDeviceID() const { return _DeviceID; }

protected:
  static void* ThreadEntryPoint(void* arg);
  void ThreadLoop();

  void Step();
  void InitDevMemory();
  void FreeDevMemory();

  void SyncFrameToHost();
  void SyncPartsToDevice();

protected:
  unsigned char _DeviceID;
  
  pthread_t _ThreadID;
  pthread_barrier_t* _Barrier;

  unsigned char* _DevFrame;
  DoF* _DevX;
  DoF* _DevY;
  VisServer* _Vis;

  double _AverageGPUTime;
  double _AverageCPUInnerTime;
  double _AverageCPUOuterTime;
  double _GPUElapsedTime;
  unsigned int _CurStep;
};

#endif
